package com.bcsq.todolistdemo.demo.activity;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.DatePicker;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import com.bcsq.todolistdemo.R;
import com.bcsq.todolistdemo.widget.DateAndTimePictureDialog;
import com.bcsq.todolistdemo.widget.DateAndTimePictureDialog.OnDateAndTimePickedListener;

import org.w3c.dom.Text;

import java.util.Calendar;
import java.util.Date;

public class AddToDoActivity extends AppCompatActivity implements View.OnClickListener {

    private Toolbar toolbar;
    private RelativeLayout timePicker;
    private Context mContext;
    private TextView tvPictedTime;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_to_do);

        init();
    }

    private void init() {
        mContext = this;
        toolbar = findViewById(R.id.toolbar);
        timePicker = findViewById(R.id.rl_time_picker);
        tvPictedTime = findViewById(R.id.tv_picture_time);
        toolbar.setTitle("添加任务");

        setSupportActionBar(toolbar);

        timePicker.setOnClickListener(this);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_confirm, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        int itemId = item.getItemId();
        switch (itemId){
            case R.id.item_confirm :
                finish();

                break;
        }
        return super.onOptionsItemSelected(item);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.rl_time_picker :
                //创建一个DateDialog对象
                DateAndTimePictureDialog.showDateAndTimePicterDialog(mContext, new OnDateAndTimePickedListener(){
                    @Override
                    public void onDateAndTimePicked(String dateTime) {
                        tvPictedTime.setText(dateTime);
                    }
                });
                break;
        }
    }


}
